package com.aitaoxue.palx.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;

import com.aitaoxue.palx.R;
import com.aitaoxue.palx.base.ListBaseAdapter;
import com.aitaoxue.palx.bean.Blog;
import com.aitaoxue.palx.util.TDevice;

public class BlogAdapter extends ListBaseAdapter {

	@Override
	protected View getRealView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null || convertView.getTag() == null) {
			convertView = getLayoutInflater(parent.getContext()).inflate(
					R.layout.list_cell_log, null);
			viewHolder = new ViewHolder(convertView);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		Blog blog = (Blog) _data.get(position);

		viewHolder.time.setText(blog.getRecord_date());
		viewHolder.name.setText(blog.getProd_name());
		
		int color=TDevice.RandomColor();
		
		viewHolder.name.setBackgroundColor(color);
		
		if (blog.getRecord_content().length() > 30) {
			viewHolder.content.setText(blog.getRecord_content()
					.substring(0, 30) + "...点击查看全部");
		} else {
			viewHolder.content.setText(blog.getRecord_content());
		}

		return convertView;
	}

	static class ViewHolder {

		@InjectView(R.id.blog_time)
		TextView time;
		@InjectView(R.id.blog_name)
		TextView name;
		@InjectView(R.id.blog_content)
		TextView content;

		public ViewHolder(View view) {
			ButterKnife.inject(this, view);
		}
	}

}
